import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import echarts from 'echarts'
import 'element-ui/lib/theme-chalk/index.css';
import {postKeyValueRequest} from "./utils/api";
import {getRequest} from "./utils/api";
import {putRequest} from "./utils/api";
import {deleteRequest} from "./utils/api";
import {postRequest} from "./utils/api";
import {initMenus} from "./utils/menu";
import $ from 'jquery';
import 'font-awesome/css/font-awesome.min.css'
import '@/styles/index.scss' // global css
import './icons' // icon
import './styles/element-variables.scss'
import AnimateCSS from 'animate.css';
// import 'normalize.css/normalize.css'
// import Antd from 'ant-design-vue';
// import 'ant-design-vue/dist/antd.css';


Vue.prototype.postKeyValueRequest=postKeyValueRequest;
Vue.prototype.getRequest=getRequest;
Vue.prototype.putRequest=putRequest;
Vue.prototype.deleteRequest=deleteRequest;
Vue.prototype.postRequest=postRequest;
Vue.prototype.$echarts = echarts;
Vue.use(ElementUI);
Vue.use(AnimateCSS);

Vue.config.productionTip = false;
// Vue.use(Antd);

router.beforeEach((to, from, next) => {
  if (to.path=='/' || to.path=='/register'){
    next();
  }else{
    if(window.sessionStorage.getItem('user')){

      initMenus(router,store);
      var modelList = [
        "https://unpkg.com/live2d-widget-model-tororo@1.0.5/assets/tororo.model.json",
        // "https://unpkg.com/live2d-widget-model-shizuku@1.0.5/assets/shizuku.model.json",
        "https://unpkg.com/live2d-widget-model-hijiki@1.0.5/assets/hijiki.model.json",
        // "https://unpkg.com/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json",
        // "https://unpkg.com/live2d-widget-model-z16@1.0.5/assets/z16.model.json",
        // "https://unpkg.com/live2d-widget-model-koharu@1.0.5/assets/koharu.model.json",
        // "https://unpkg.com/live2d-widget-model-miku/assets/miku.model.json",
        // "https://unpkg.com/live2d-widget-model-chitose/assets/chitose.model.json",
        // "https://unpkg.com/live2d-widget-model-haruto/assets/haruto.model.json"
      ]
      // var m = randomNum(0,modelList.length-1)
      var m = JSON.parse(window.sessionStorage.getItem("user")).sex
      if(L2Dwidget){
        L2Dwidget.init({
          "model": {
            jsonPath: modelList[m],
            "scale": 1
          },
          "display": {
            "position": "left",
            "width": 100,
            "height": 160,
            "hOffset": 0,
            "vOffset": -30
          },
          "mobile": {
            "show": true,
            "scale": 0.5
          },
          "react": {
            "opacityDefault": 0.9,
            "opacityOnHover": 0.2
          }
        });
      }
      next();
    }else {
      next('/?redirect='+to.path);
    }
  }
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
